package org.barman.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.barman.exception.PersistenceException;

public class DbHelper {

	private static final String databaseName = "barman";
	private static final String databaseUser = "root";
	private static final String databasePassword = "";

	public static Connection getConnection() throws PersistenceException {
		try {
			Class.forName("com.mysql.jdbc.Driver");

			Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/" + databaseName + "?"
					+ "user=" + databaseUser + "&password=" + databasePassword);

			return connection;
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new PersistenceException(e.getMessage());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new PersistenceException(e.getMessage());
		}
	}
}
